﻿Public Class Log

    Private Sub Log_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.Test4DataSet.EnforceConstraints = False
        'Me.Tbl_test_logTableAdapter.Fill(Me.Test4DataSet.tbl_test_log)
        'Me.Tbl_testTableAdapter.Fill(Me.Test4DataSet.tbl_test)
        'Me.Tbl_test_logIUltraGrid.setDoiTuongXuLyDuLieu(Me.Test4DataSet.tbl_test_log, Me.Tbl_test_logBindingSource, Me.Tbl_test_logTableAdapter, Me.Test4DataSet)
        Me.Tbl_testIUltraGrid.setDoiTuongXuLyDuLieu(Me.Test4DataSet.tbl_test, Me.Tbl_testBindingSource, Me.Tbl_testTableAdapter, Me.Test4DataSet)
        Me.Tbl_test_logIUltraGrid.setGiaoDienTuDong()
        Me.Tbl_testIUltraGrid.setGiaoDienTuDong()
        Me.Tbl_test_logIUltraGrid.setChoPhepMenuStrip()
        Me.Tbl_testIUltraGrid.setChoPhepMenuStrip()
        'Me.Tbl_test_logTableAdapter.InsertQuery.ParamArray()
    End Sub
    Private Sub getEdit()
        Dim dtEdit As test4DataSet.tbl_testDataTable = GetEditRecords()

    End Sub
    Private Sub getNew()
        Dim dtNew As test4DataSet.tbl_testDataTable = GetNewRecords()
        'Dim dtEdit As test4DataSet.tbl_testDataTable = GetEditRecords()
        'Dim dtDelete As test4DataSet.tbl_testDataTable = GetDeleteRecords()
        'If dtNew IsNot Nothing And dtEdit IsNot Nothing Then
        '    dtNew.Merge(dtEdit)
        '    Me.Tbl_test_logIUltraGrid.DataSource = dtNew
        'End If
        'If dtNew IsNot Nothing And dtDelete IsNot Nothing Then
        '    dtNew.Merge(dtDelete)
        '    Me.Tbl_test_logIUltraGrid.DataSource = dtNew
        'End If
        'If dtEdit IsNot Nothing And dtDelete IsNot Nothing Then
        '    dtEdit.Merge(dtDelete)
        '    Me.Tbl_test_logIUltraGrid.DataSource = dtEdit
        'End If
        If dtNew IsNot Nothing Then
            Me.Tbl_test_logIUltraGrid.DataSource = dtNew
        End If
        'If dtDelete IsNot Nothing Then
        '    MessageBox.Show(dtDelete.Rows.Count)
        '    Me.Tbl_test_logIUltraGrid.DataSource = GetDeleteRecords()
        'End If
        'If dtEdit IsNot Nothing Then
        '    Me.Tbl_test_logIUltraGrid.DataSource = dtEdit
        'End If
        'GetNewRecords().Merge(dtEdit)


    End Sub
    Private Function GetNewRecords() As test4DataSet.tbl_testDataTable
        Return CType(Test4DataSet.tbl_test.GetChanges(Data.DataRowState.Added),  _
            test4DataSet.tbl_testDataTable)
    End Function
    Private Function GetEditRecords() As test4DataSet.tbl_testDataTable

        Return CType(Test4DataSet.tbl_test.GetChanges(Data.DataRowState.Modified),  _
            test4DataSet.tbl_testDataTable)
    End Function
    Private Function GetDeleteRecords() As test4DataSet.tbl_testDataTable

        Return CType(Test4DataSet.tbl_test.GetChanges(Data.DataRowState.Deleted),  _
            test4DataSet.tbl_testDataTable)
    End Function

    Private Sub UltraButton1_Click(sender As System.Object, e As System.EventArgs) Handles UltraButton1.Click
        'Me.Tbl_test_logIUltraGrid.DataSource = 
        'If Me.Tbl_testIUltraGrid.getCoThayDoiDuLieuKhong Then
        '    Me.Tbl_testIUltraGrid.UpdateData()
        '    getThaoTac()
        'End If
        'Me.Tbl_test_logIUltraGrid.DataSource = Me.Test4DataSet.GetChanges()
       
        Me.Tbl_testIUltraGrid.UpdateData()
        Dim deletedChildRecords As test4DataSet.tbl_testDataTable = _
        CType(Test4DataSet.tbl_test.GetChanges(Data.DataRowState.Deleted), test4DataSet.tbl_testDataTable)

        Dim newChildRecords As test4DataSet.tbl_testDataTable = _
        CType(Test4DataSet.tbl_test.GetChanges(Data.DataRowState.Added), test4DataSet.tbl_testDataTable)

        Dim modifiedChildRecords As test4DataSet.tbl_testDataTable = _
        CType(Test4DataSet.tbl_test.GetChanges(Data.DataRowState.Modified), test4DataSet.tbl_testDataTable)

        'Test4DataSet.a

        'If Test4DataSet.tbl_test.DefaultView.RowStateFilter = DataViewRowState.Deleted Then
        '    MessageBox.Show(Test4DataSet.tbl_test.DefaultView.Item("id").ToString())
        '    'MessageBox.Show(dataRow["CustomerID", DataRowVersion.Original)
        '    'Dim DV As DataView = deletedChildRecords.DA
        '    'Tbl_test_logTableAdapter.Update(deletedChildRecords)
        '    'Dim row As DataRow = Nothing
        '    'For index = 0 To deletedChildRecords.Rows.Count - 1
        '    '    row(index) = deletedChildRecords.Rows(index, DataRowVersion.Original)
        '    'Next
        '    'Me.Tbl_test_logIUltraGrid.DataSource = deletedChildRecords
        '    'Dim row As DataTable
        '    'Dim index As Integer = 0
        '    'Dim dt As DataTable
        '    'For Each row In deletedChildRecords.Rows
        '    '    index = index + 1
        '    '    'row(index, DataRowVersion.Original)
        '    '    'row(DataRowVersion.Original)
        '    '    dt.
        '    '    'Me.Tbl_test_logIUltraGrid.Rows
        '    'Next row
        '    'Me.Tbl_test_logIUltraGrid.DataSource = dt
        '    'If Me.Test4DataSet.tbl_testRow.roThen Then

        'End If
        If deletedChildRecords IsNot Nothing Then
            'MessageBox.Show(deletedChildRecords.Rows.Count())
            'Dim row As DataRowView
            'For index = 0 To deletedChildRecords.DefaultView.Count - 1
            '    If row(index
            '        Dim ma As String = deletedChildRecords.DefaultView.ro
            'Next
            'MessageBox.Show(deletedChildRecords.DefaultView.Count)

        End If
        'If modifiedChildRecords IsNot Nothing And newChildRecords IsNot Nothing Then
        '    modifiedChildRecords.Merge(newChildRecords)
        '    Me.Tbl_test_logIUltraGrid.DataSource = modifiedChildRecords

        'End If
        If newChildRecords IsNot Nothing Then
            'Tbl_test_logTableAdapter.Update(deletedChildRecords)
            Me.Tbl_test_logIUltraGrid.DataSource = newChildRecords
            For index = 0 To Me.Tbl_test_logIUltraGrid.Rows.Count - 1
                Me.Tbl_test_logIUltraGrid.Rows(index).Cells("nguoidung").Value = "nguoidung"
                Me.Tbl_test_logIUltraGrid.Rows(index).Cells("thaotac").Value = "0"
                Me.Tbl_test_logIUltraGrid.Rows(index).Cells("thoigian").Value = Date.Now
                Me.Tbl_test_logIUltraGrid.Rows(index).Cells("chinhanh").Value = "chinhanh"
            Next
            'Me.Tbl_test_logIUltraGrid.DataSource = Me.Test4DataSet.tbl_test_log.ImportRow

            'Me.Tbl_test_logIUltraGrid.getLuu()

            ''newChildRecords.AcceptChanges()
        End If
        If modifiedChildRecords IsNot Nothing Then
            'Tbl_test_logTableAdapter.Update(deletedChildRecords)
            Me.Tbl_test_logIUltraGrid.DataSource = modifiedChildRecords
            'modifiedChildRecords.AcceptChanges()
        End If
        'Me.Tbl_test_logTableAdapter.in()
    End Sub

    Private Sub Tbl_testIUltraGrid_BeforeRowsDeleted(sender As Object, e As Infragistics.Win.UltraWinGrid.BeforeRowsDeletedEventArgs) Handles Tbl_testIUltraGrid.BeforeRowsDeleted
    End Sub

    Private Sub UltraButton2_Click(sender As System.Object, e As System.EventArgs) Handles UltraButton2.Click
        'Me.Tbl_test_logIUltraGrid.UpdateData()
        'Me.Tbl_test_logBindingSource.EndEdit()
        'Me.Tbl_test_logTableAdapter.Update(Me.Test4DataSet.tbl_test_log)
        '    Dim row As test4DataSet.tbl_test_logRow = Me.Test4DataSet.tbl_test_log.Newtbl_test_logRow()
        '    For index = 0 To Me.Tbl_test_logIUltraGrid.Rows.Count - 1
        '        For index1 = 0 To Me.Tbl_test_logIUltraGrid.DisplayLayout.Bands(0).Columns.Count - 1
        '            row.Item(index1) = Me.Tbl_test_logIUltraGrid.Rows(index).Cells(Me.Tbl_test_logIUltraGrid.DisplayLayout.Bands(0).Columns(index1).Key).Value

        '        Next
        '        Me.Test4DataSet.tbl_test_log.Addtbl_test_logRow(row)
        '    Next
        '    Me.Tbl_test_logTableAdapter.Update(Me.Test4DataSet.tbl_test_log)
    End Sub
End Class